package cn.eeany.zutools.index

import cn.eeany.zutools.index.service.impl.FileService
import org.mapdb.DB
import org.mapdb.DBMaker
import org.mapdb.Serializer
import org.springframework.stereotype.Service

import java.util.concurrent.ConcurrentMap

@Service
class DbSetting {
    static final String dbPath = "X:\\01"

//    def fileDbPath="${dbPath}\\fileIndex"
    static void main(String[] args) {
        DbSetting dbSetting = new DbSetting()
        def file = new File("Y:\\smcp-workorder-customer")
        dbSetting.indexFile(file)


    }

    def indexFile(def file) {
        FileService fileService = new FileService()
        if (file.isDirectory()) {
            file.eachFile { it -> fileService.readFile(it)  }
            file.eachDir { it ->indexFile(it) }
        }
    }

    def static getDB() {
        DB db = DBMaker
                .fileDB("%{fileDbPath}\\file.db")
                .fileMmapEnable()
                .make();
        ConcurrentMap<String, Long> map = db
                .hashMap("filelist", Serializer.STRING, Serializer.STRING)
                .createOrOpen();

    }

    def closeDb(def db) {
        if (db != null) {
            db.close()
        }
    }
}
